<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <title>管理员列表</title>
</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="row m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i>  <a>系统管理</a>
                    </li>
                    <li class="active">
                        <strong>管理员列表</strong>
                    </li>
                </ol>
                <span class="navbar-right  m-r m-t-8"><a href="${ctx}/admin/sys/admin/add" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i> 新 增</a></span>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox">
                        <div class="ibox-content">
                            <div class="search-area">
                                <form role="form" class="form-inline" id="queryform">
                                    <label for="username">
                                        <input type="input" placeholder="账号" name="usernameLike"
                                               id="username"
                                               class="form-control form-filter"></label>
                                    <label for="name">
                                    <input type="input" placeholder="姓名" name="nameLike"
                                           id="name"
                                           class="form-control form-filter"></label>
                                    <label for="tel">
                                        <input type="input" placeholder="联系电话" name="telLike"
                                               id="tel"
                                               class="form-control form-filter"></label>
                                    <label for="adminState">
                                        <select class="form-control  form-filter" name="adminState" id="adminState">
                                            <option value="">--状态--</option>
                                            <option value="0">使用中</option>
                                            <option value="1">已注销</option>
                                        </select>

                                    </label>
                                    <label for="role">
                                        <select class="form-control  form-filter" name="role" id="role">
                                            <option value="">--角色--</option>
                                            <c:forEach items="${roles}" var="role">
                                                <option value="${role.roleId}">${role.roleName}</option>
                                            </c:forEach>
                                        </select>
                                    </label>
                                    <button class="btn btn-primary" type="button" onclick="submitFilter()"> 查询</button>
                                    <button class="btn btn-primary" datatable-clear type="button"> 清除</button>
                                </form>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover dataTables" id="data-table"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>


<!-- Page-Level Scripts -->
<script>
    $(document).ready(function () {
        var setting = {
            "ajax": {
                "url": "${ctx}/admin/sys/admin/list",
                "type": "POST"
            },
            "columns": [
                {"title": "账号", "data": "username", "width": "12%", "orderable": true},
                {"title": "姓名", "data": "name", "width": "12%", "orderable": true},
                {"title": "联系电话", "data": "tel", "width": "14%", "orderable": true},
                {"title": "角色", "data": "roles", "width": "20%", "orderable": false},
                {"title": "职位", "data": "position", "width": "16%", "orderable": true},
                {"title": "状态", "data": "adminState", "width": "12%", "orderable": true},
                {"title": "操作", "data": null, "width": "14%", "orderable": false},
                {"title": "时间", "data": "createTime","name":"create_time","visible":false}

            ],
            "columnDefs": [
                {
                    "targets": 5,
                    "render": function (data, type, row, meta) {
                        return ((data==0&&"使用中")||(data==1&&"已注销")||"--");
                    }
                },
                {
                    "targets": 6,
                    "render": function (data, type, row, meta) {
                        var forbid_data="";
                        var forbid_title="";
                        if(data.adminState==1){
                            forbid_title="启用";
                            forbid_data = '{"id":" '+ data.adminId +' ","status":0}';
                        }else{
                            forbid_title="注销"
                            forbid_data = '{"id":" '+ data.adminId +' ","status":1}';
                        }

                        return  ((data.adminState==0||"")&&"<a class='btn btn-xs default btn-editable' href='${ctx}/admin/sys/admin/update?id=" + data.adminId + "'><i class='fa fa-pencil-square-o'></i>编辑 </a>") +
                                "<a class='btn btn-xs default btn-editable' data-opt data-opt-url='${ctx}/admin/sys/admin/forbid' data-opt-pams='"+forbid_data+"' data-opt-fun='$(\"#data-table\").DataTable().draw();'  ><i class='fa fa-ban'></i> "+forbid_title+" </a>";
                                <%--"<a class='btn btn-xs default btn-editable' href='${ctx}/admin/sys/admin/detail?id=" + data.adminId + "'><i class='fa fa-file-text-o'></i>详情 </a>" ;--%>
                    },
                    "orderable": false
                }
            ],
            "order": [
                [7, "desc"]
            ],
        };
        /* Init DataTables */
        $('#data-table').DataTable(ehconfig.get_datatable_config(setting));
        submitFilter = function () {
            $('#data-table').DataTable().draw();
        }
    });
//    function clean() {
//        $('#username').val('');
//        $('#name').val('');
//        $('#tel').val('');
//        $('#data-table').DataTable().draw();
//    }
</script>

</body>

</html>
